import React from "react";
import { HashRouter, Route, Switch, Redirect } from "react-router-dom";
import { connect } from "react-redux";
import Layout from "@/views/layout";
import Login from "@/views/login/index";
import PATH_MAP from '@/config/pathConstance';
class Router extends React.Component {
  render() {
    const { token, role } = this.props;
    return (
      <HashRouter>
        <Switch>
          <Route exact path={PATH_MAP.LOGIN} component={Login} />
          <Route
            path="/"
            render={() => {
              if (!token) {
                return <Redirect to={PATH_MAP.LOGIN} />;
              } else {
                if (role) {
                  return <Layout />;
                }
              }
            }}
          />
        </Switch>
      </HashRouter>
    );
  }
}

export default connect((state) => state.user)(Router);
